package cn.mengxw.evcard.entity.cmd;

import cn.mengxw.evcard.config.ConfigManage;
import org.apache.commons.lang3.StringUtils;
import org.meowy.cqp.jcq.entity.CoolQ;
import org.meowy.cqp.jcq.entity.Group;

import java.util.List;

public class SendGroupMessage extends BaseCommand {

  public SendGroupMessage(CoolQ CQ, Command command, Long fromQQ) {
    super(CQ, command, fromQQ);
  }

  @Override
  public void run() {
    List<Long> groupIds = command.getList();
    if (StringUtils.equals(command.getRange(), "part")
        && groupIds != null
        && groupIds.size() != 0) {
      // 指定了群列表
      groupIds.forEach(groupId -> CQ.sendGroupMsg(groupId, command.getMsg()));
    } else if (StringUtils.equals(command.getRange(), "all")) {
      CQ.getGroupList().stream()
          .map(Group::getId)
          .forEach(groupId -> CQ.sendGroupMsg(groupId, command.getMsg()));
    } else {
      ConfigManage.getenableRobotSet().stream()
          .forEach(groupId -> CQ.sendGroupMsg(groupId, command.getMsg()));
    }
    CQ.sendPrivateMsg(fromQQ, "群消息已经发送完毕！");
  }
}
